<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>onScrollStop</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .scroll {
            min-height: 200vh;
            display: flex;
            justify-content: center;
            margin-top: 2em;
        }
    </style>
</head>

<body>
    <div class="scroll">滚动页面看看效果</div>
    <script>
        const onScrollStop = (callback, n = 150) => {
            let timer, isScrolling = false;
            window.addEventListener('scroll', e => {
                isScrolling = false;
                if (timer) {
                    clearTimeout(timer);
                }
                timer = setTimeout(() => {
                    isScrolling = true;
                    callback?.(e, isScrolling);
                }, n);
            }, false)
        }
        onScrollStop((e,isScrolling) => {
            alert("滚动" + (isScrolling ? "" : "未") + "停止");
            console.log(isScrolling,'The user has stopped scrolling');
        })
    </script>
</body>

</html>